import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

public class MyBlockQueue {
    public String[] elem = null;
    int head = 0;
    int tail = 0;
    int size = 0;
    Object object = new Object();

    public MyBlockQueue(int capacity) {
        this.elem = new String[capacity];
    }
    public void put(String e) throws InterruptedException {
        synchronized (object) {

            while(size >= elem.length) {
                object.wait();
            }
            elem[tail] = e;
            tail++;
            if (tail >= elem.length) {
                tail = 0;
            }
            size++;
            object.notify();
        }
    }
    public String take() throws InterruptedException {
        synchronized (object){
            while(elem.length<= 0){
                object.wait();
            }
String e = elem[head];
        head++;
        if(head>=elem.length){
            head = 0;
        }
        size--;
        object.notify();
      return e;
    }
}
}
